#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2021/3/17 11:43
# @Author : linjinting
# @Project : Flask-WebService
# @File : readconfig.py
# @Software: PyCharm


import configparser
import os


class ReadConfig(object):
    """定义一个读取配置文件的类"""

    def __init__(self, filepath=None):
        self.m_config_dict = dict()
        if filepath:
            _path = filepath
        else:
            root_dir = os.path.abspath('.')
            _path = os.path.join(root_dir, "config\config.ini")
        self.m_config = configparser.ConfigParser()
        self.m_config.read(_path)
        self.__as_dict()

    def __as_dict(self):
        d = dict(self.m_config._sections)
        for k in d:
            self.m_config_dict[k] = dict(d[k])

    def get_config(self):
        return self.m_config

    def get_config_dict(self):
        return self.m_config_dict

